package com.kaili.basic.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.kaili.basic.mapper.BaseInStoreMapper;
import com.kaili.basic.pojo.dto.BaseInStoreQueryDto;
import com.kaili.basic.pojo.entity.BaseInStoreEntity;
import com.kaili.basic.pojo.vo.BaseInStoreDetailVO;
import com.kaili.basic.pojo.vo.BaseInStoreExportVO;
import com.kaili.basic.service.BaseInStoreDetailService;
import com.kaili.basic.service.BaseInStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class BaseInStoreServiceImpl extends ServiceImpl<BaseInStoreMapper, BaseInStoreEntity> implements BaseInStoreService {

    @Autowired
    private BaseInStoreMapper baseInStoreMapper;

    @Autowired
    private BaseInStoreDetailService baseInStoreDetailService;

    @Override
    public Long queryStoreOrderNo() {
        return baseInStoreMapper.queryStoreOrderNo();
    }

    @Override
    public Page<BaseInStoreDetailVO> queryPageList(Page<BaseInStoreDetailVO> page, BaseInStoreQueryDto queryDto) {
        List<BaseInStoreDetailVO> list = baseInStoreMapper.queryPageList(page, queryDto);
        page.setRecords(list);
        return page;
    }

    @Override
    public List<BaseInStoreExportVO> export(BaseInStoreQueryDto queryDto) {
        return baseInStoreMapper.inStoreExport(queryDto);
    }

    @Override
    public BaseInStoreDetailVO queryInStoreDetail(Map<String, Object> map) {
        BaseInStoreDetailVO detailVO = baseInStoreMapper.queryPageList(map);
        List<BaseInStoreDetailVO> list = baseInStoreDetailService.queryDetailByOrderNo(new HashMap<String, Object>() {{
            put("orderNo", detailVO.getOrderNo());
        }});
        detailVO.setList(list);
        return detailVO;
    }
}
